package com.bt.lms.ui.page.enp;

import com.bt.lms.ui.action.enp.*;
import com.bt.lms.main.BotLmsApp;
import com.bt.lms.ui.page.sys.style.BtnStyle;
import com.bt.lms.ui.vo.enp.EnrollmentPlanListVo;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;

import java.util.ArrayList;
import java.util.List;

/**
 * 招生计划数据界面
 */
public class EnrollmentPlanList extends VBox {

    private Integer width = BotLmsApp.PER_WIGHT;
    private Integer height = BotLmsApp.HEIGHT;

    /**
     * 表格
     */
    public TableView tableView;

    public EnrollmentPlanList() {

        this.setPrefHeight(height);
        this.setPrefWidth(width);


        //当前位置
        HBox locationHBox = new HBox();
        locationHBox.setPadding(new Insets(15, 15, 15, 15));
        locationHBox.setPrefWidth(width);
        double locationHBoxHeight = height * 0.1;
        locationHBox.setPrefHeight(locationHBoxHeight);
        Label label1 = new Label("当前位置：🏠>招生管理>招生计划管理");
        Font font = Font.font("仿宋", FontWeight.THIN, FontPosture.REGULAR, 18);
        label1.setFont(font);
        locationHBox.getChildren().add(label1);
        this.getChildren().add(locationHBox);


        //分页查询
        VBox topVBox = new VBox();
        topVBox.setPadding(new Insets(15, 15, 15, 15));

        double topHBoxHeight = height * 0.1;
        topVBox.setPrefHeight(topHBoxHeight);
        topVBox.setPrefWidth(width);
        topVBox.setSpacing(20);

        //上盒子
        HBox hBox = new HBox();
        hBox.setSpacing(30);

        Label label = new Label("模糊查询");
        TextField nameTf = new TextField();
        nameTf.setPromptText("请输入招生计划名称");
        nameTf.setId("nameTf");

        ComboBox<Object> statusCom = new ComboBox<>();
        statusCom.setCursor(Cursor.HAND); //鼠标移入添加小手图案
        statusCom.getSelectionModel().select("计划状态");
        statusCom.getItems().add("未开始");
        statusCom.getItems().add("报名中");
        statusCom.getItems().add("审核中");
        statusCom.getItems().add("已完成");
        statusCom.getItems().add("全部");
        statusCom.setId("statusCom");
        hBox.getChildren().addAll(label, nameTf, statusCom);

        //下盒子
        HBox bottomHBox = new HBox();
        bottomHBox.setSpacing(30);
        ComboBox<Object> timeCom = new ComboBox<>();
        timeCom.setCursor(Cursor.HAND); //鼠标移入添加小手图案
        timeCom.getSelectionModel().select("按开始时间查询");
        timeCom.getItems().add("按截至时间查询");
        timeCom.setId("timeCom");
        DatePicker startTimeDp = new DatePicker();//开始时间
        startTimeDp.setId("startTimeDp");

        Label separatorLb = new Label("至");

        DatePicker stopTimeDp = new DatePicker(); //结束时间
        stopTimeDp.setId("stopTimeDp");

        Button searchBtn = new Button("搜索");
        searchBtn.setCursor(Cursor.HAND); //鼠标移入添加小手图案
        searchBtn.setStyle("-fx-background-color: #00a6ff");
        bottomHBox.getChildren().addAll(timeCom, startTimeDp, separatorLb, stopTimeDp, searchBtn);
        //搜索按钮事件
        SearchBtnAction searchBtnAction = new SearchBtnAction(this);
        searchBtn.setOnAction(searchBtnAction);

        topVBox.getChildren().addAll(hBox, bottomHBox);
        this.getChildren().add(topVBox);


        //新增/导出按钮
        HBox btnHBox = new HBox();
        btnHBox.setPadding(new Insets(15, 15, 15, 15));
        btnHBox.setSpacing(20);
        btnHBox.setPrefWidth(width);
        double btnHBoxHeight = height * 0.05;
        btnHBox.setPrefHeight(btnHBoxHeight);
        Button addBtn = new Button("新增招生计划");
        addBtn.setCursor(Cursor.HAND);
        BtnStyle.addBtn(addBtn);
        addBtn.setPrefWidth(150);
        addBtn.setPrefHeight(40);
        btnHBox.getChildren().add(addBtn);
        this.getChildren().add(btnHBox);

        //事件
        AddEnrollmentPlanBtnAction addEnrollmentPlanAction = new AddEnrollmentPlanBtnAction();
        addBtn.setOnAction(addEnrollmentPlanAction);


        //创建一个表格组件
        tableView= new TableView();
//      table.setTableMenuButtonVisible(false);
        tableView.setPrefWidth(width);
        tableView.setPrefHeight(height * 0.65);
        //创建列
        TableColumn codeCol = new TableColumn<>("招生计划编号");
        TableColumn nameCol = new TableColumn<>("招生计划名称");
        TableColumn levelCol = new TableColumn<>("招生层次");
        TableColumn specialtyCol = new TableColumn<>("招生专业");
        TableColumn teachingPlan = new TableColumn<>("关联教学计划");
        TableColumn studyCentre = new TableColumn<>("学习中心");
        TableColumn startTimeCol = new TableColumn<>("开始时间");
        TableColumn stopTimeCol = new TableColumn<>("截止时间");
        TableColumn enPopulationCol = new TableColumn<>("计划招生人数");
        TableColumn applyPopulationCol = new TableColumn<>("报名人数");
        TableColumn checkPopCol = new TableColumn<>("审核通过人数");
        TableColumn admitCol = new TableColumn<>("录取人数");
        TableColumn stateCol = new TableColumn<>("状态");
        TableColumn startStateCol = new TableColumn<>("启用状态");
        TableColumn operateCol = new TableColumn<>("操作");


        //把列放入表格
        ObservableList columns = tableView.getColumns();
        columns.addAll(codeCol, nameCol, levelCol, specialtyCol, teachingPlan, studyCentre, startTimeCol, stopTimeCol, enPopulationCol, applyPopulationCol, checkPopCol, admitCol, stateCol, startStateCol, operateCol);

        //加入数据放入表格中
        //招生计划名称盒子(数据1)
        HBox nameHBox1 = new HBox();
        Label nameLb = new Label("网联培训计划");
        Color color = Color.rgb(99, 212, 238, 1);
        nameLb.setTextFill(color);
        nameHBox1.getChildren().add(nameLb);

        //加事件
        CheckEnrollmentPlanDetailsAction checkEnrollmentPlanDetailsAction = new CheckEnrollmentPlanDetailsAction();
        nameLb.setOnMouseClicked(checkEnrollmentPlanDetailsAction);
        //招生计划名称盒子(数据2)
        HBox nameHBox2 = new HBox();
        Label naneLb2 = new Label("网联培训计划");
        naneLb2.setTextFill(color);
        nameHBox2.getChildren().add(naneLb2);
        //加事件
        CheckEnrollmentPlanDetailsAction checkEnrollmentPlanDetailsAction1 = new CheckEnrollmentPlanDetailsAction();
        naneLb2.setOnMouseClicked(checkEnrollmentPlanDetailsAction1);
        //招生计划名称盒子(数据3)
        HBox nameHBox3 = new HBox();
        Label nameLb3 = new Label("网联培训计划");
        nameLb3.setTextFill(color);
        nameHBox3.getChildren().add(nameLb3);
        //加事件
        CheckEnrollmentPlanDetailsAction checkEnrollmentPlanDetailsAction2 = new CheckEnrollmentPlanDetailsAction();
        nameLb3.setOnMouseClicked(checkEnrollmentPlanDetailsAction2);
        //招生计划名称盒子(数据4)
        HBox nameHBox4 = new HBox();
        Label nameLb4 = new Label("网联培训计划");
        nameLb4.setTextFill(color);
        nameHBox4.getChildren().add(nameLb4);
        //加事件
        CheckEnrollmentPlanDetailsAction checkEnrollmentPlanDetailsAction3 = new CheckEnrollmentPlanDetailsAction();
        nameLb4.setOnMouseClicked(checkEnrollmentPlanDetailsAction3);
        //招生计划名称盒子(数据5)
        HBox nameHBox5 = new HBox();
        Label nameLb5 = new Label("网联培训计划");
        nameLb5.setTextFill(color);
        nameHBox5.getChildren().add(nameLb5);
        //加事件
        CheckEnrollmentPlanDetailsAction checkEnrollmentPlanDetailsAction4 = new CheckEnrollmentPlanDetailsAction();
        nameLb5.setOnMouseClicked(checkEnrollmentPlanDetailsAction4);
        //消极颜色
        Color rgb = Color.rgb(140, 140, 140);
        //操作盒子（数据1）
        HBox operateHBox1 = new HBox();
        operateHBox1.setSpacing(5);
        Label editLb1 = new Label("编辑");
        editLb1.setTextFill(color);
        Label enableLb1 = new Label("启用");
        enableLb1.setTextFill(color);
        Label pauseLb1 = new Label("暂停");
        pauseLb1.setTextFill(rgb);
        Label deleteLb1 = new Label("删除");
        deleteLb1.setTextFill(color);
        Label accomplishLb1 = new Label("完成");
        accomplishLb1.setTextFill(rgb);
        operateHBox1.getChildren().addAll(editLb1, enableLb1, pauseLb1, deleteLb1, accomplishLb1);
        //编辑按钮加事件
        EditEnrollmentPlanAction editEnrollmentPlanAction = new EditEnrollmentPlanAction();
        editLb1.setOnMouseClicked(editEnrollmentPlanAction);
        //删除按钮加事件
        DeleteEnrollmentPlanAction deleteEnrollmentPlanAction = new DeleteEnrollmentPlanAction(this);
        deleteLb1.setOnMouseClicked(deleteEnrollmentPlanAction);


        //操作盒子（数据2）
        HBox operateHBox2 = new HBox();
        operateHBox2.setSpacing(5);
        Label editLb2 = new Label("编辑");
        editLb2.setTextFill(rgb);
        Label enableLb2 = new Label("启用");
        enableLb2.setTextFill(rgb);
        Label pauseLb2 = new Label("暂停");
        pauseLb2.setTextFill(rgb);
        Label deleteLb2 = new Label("删除");
        deleteLb2.setTextFill(rgb);
        Label accomplishLb2 = new Label("完成");
        accomplishLb2.setTextFill(rgb);
        operateHBox2.getChildren().addAll(editLb2, enableLb2, pauseLb2, deleteLb2, accomplishLb2);
        //操作盒子（数据3）
        HBox operateHBox3 = new HBox();
        operateHBox3.setSpacing(5);
        Label editLb3 = new Label("编辑");
        editLb3.setTextFill(rgb);
        Label enableLb3 = new Label("启用");
        enableLb3.setTextFill(rgb);
        Label pauseLb3 = new Label("暂停");
        pauseLb3.setTextFill(color);
        Label deleteLb3 = new Label("删除");
        deleteLb3.setTextFill(rgb);
        Label accomplishLb3 = new Label("完成");
        accomplishLb3.setTextFill(rgb);
        operateHBox3.getChildren().addAll(editLb3, enableLb3, pauseLb3, deleteLb3, accomplishLb3);
        //操作盒子（数据4）
        HBox operateHBox4 = new HBox();
        operateHBox4.setSpacing(5);
        Label editLb4 = new Label("编辑");
        editLb4.setTextFill(rgb);
        Label enableLb4 = new Label("启用");
        enableLb4.setTextFill(rgb);
        Label pauseLb4 = new Label("暂停");
        pauseLb4.setTextFill(rgb);
        Label deleteLb4 = new Label("删除");
        deleteLb4.setTextFill(rgb);
        Label accomplishLb4 = new Label("完成");
        accomplishLb4.setTextFill(color);
        operateHBox4.getChildren().addAll(editLb4, enableLb4, pauseLb4, deleteLb4, accomplishLb4);
        //操作盒子（数据5）
        HBox operateHBox5 = new HBox();
        operateHBox5.setSpacing(5);
        Label editLb5 = new Label("编辑");
        editLb5.setTextFill(color);
        Label enableLb5 = new Label("启用");
        enableLb5.setTextFill(rgb);
        Label pauseLb5 = new Label("暂停");
        pauseLb5.setTextFill(color);
        Label deleteLb5 = new Label("删除");
        deleteLb5.setTextFill(color);
        Label accomplishLb5 = new Label("完成");
        accomplishLb5.setTextFill(color);
        operateHBox5.getChildren().addAll(editLb5, enableLb5, pauseLb5, deleteLb5, accomplishLb5);
        //加事件
        FiveEditEnrollmentPlanAction fiveEditEnrollmentPlanAction = new FiveEditEnrollmentPlanAction();
        editLb5.setOnMouseClicked(fiveEditEnrollmentPlanAction);


        EnrollmentPlanListVo enrollmentPlanListVo01 = new EnrollmentPlanListVo("1", nameHBox1, "西南大学", "免费师范生", "济南", "2023夏季教学计划", "2009/09/08", "2009/09/08", "468", "0", "0", "0", "未开始", "暂停", operateHBox1);
        EnrollmentPlanListVo enrollmentPlanListVo02 = new EnrollmentPlanListVo("2", nameHBox2, "西南大学", "免费师范生", "济南", "2023夏季教学计划", "2009/09/08", "2009/09/08", "468", "3232", "10", "5", "已完成", "启用", operateHBox2);
        EnrollmentPlanListVo enrollmentPlanListVo03 = new EnrollmentPlanListVo("3", nameHBox3, "西南大学", "免费师范生", "济南", "2023夏季教学计划", "2009/09/08", "2009/09/08", "468", "3232", "10", "5", "报名中", "启用", operateHBox3);
        EnrollmentPlanListVo enrollmentPlanListVo04 = new EnrollmentPlanListVo("4", nameHBox4, "西南大学", "免费师范生", "济南", "2023夏季教学计划", "2009/09/08", "2009/09/08", "468", "3232", "10", "5", "审核中", "启用", operateHBox4);
        EnrollmentPlanListVo enrollmentPlanListVo05 = new EnrollmentPlanListVo("5", nameHBox5, "西南大学", "免费师范生", "济南", "2023夏季教学计划", "2009/09/08", "2009/09/08", "468", "3232", "10", "5", "未开始", "启用", operateHBox5);

        //放入集合
        List<EnrollmentPlanListVo> enrollmentPlanListVo = new ArrayList<>();
        enrollmentPlanListVo.add(enrollmentPlanListVo01);
        enrollmentPlanListVo.add(enrollmentPlanListVo02);
        enrollmentPlanListVo.add(enrollmentPlanListVo03);
        enrollmentPlanListVo.add(enrollmentPlanListVo04);
        enrollmentPlanListVo.add(enrollmentPlanListVo05);

        //将用户数据集合转成Javafx组件集合
        ObservableList<EnrollmentPlanListVo> enrollmentPlanListVos = FXCollections.observableArrayList(enrollmentPlanListVo);
        //把数据放入表格中
        tableView.setItems(enrollmentPlanListVos);

        //映射
        codeCol.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, Integer>("code"));
        nameCol.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("planName"));
        levelCol.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("level"));
        specialtyCol.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("major"));
        teachingPlan.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("teachingPlan"));
        studyCentre.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("studyCentre"));
        startTimeCol.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("startTime"));
        stopTimeCol.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("stopTime"));
        enPopulationCol.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("enPopulation"));
        applyPopulationCol.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("applyPopulation"));
        checkPopCol.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("checkPop"));
        admitCol.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("admit"));
        stateCol.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("status"));
        startStateCol.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("startStatus"));
        operateCol.setCellValueFactory(new PropertyValueFactory<EnrollmentPlanListVo, String>("operate"));

        this.getChildren().add(tableView);//放入主盒子


        //分页查询
        HBox hBox2 = new HBox();
        hBox2.setSpacing(6);
        hBox2.setAlignment(Pos.CENTER_RIGHT);
        Label firstLab  = new Label("<<首页");
        firstLab.setCursor(Cursor.HAND); //鼠标移入添加小手图案
        EnpPageAction enpPageAction = new EnpPageAction(this,tableView);
        firstLab.setOnMouseClicked(enpPageAction);
        //颜色
        Color rgb3 = Color.rgb(120,185,0);
        firstLab.setTextFill(rgb3);
        Label upLab = new Label("<<上一页");
        upLab.setCursor(Cursor.HAND); //鼠标移入添加小手图案
        upLab.setTextFill(rgb3);
        upLab.setOnMouseClicked(enpPageAction);

        Button oneLab = new Button("1");
        oneLab.setCursor(Cursor.HAND); //鼠标移入添加小手图案
        oneLab.setOnMouseClicked(enpPageAction);

        Button twoBtn = new Button("2");
        twoBtn.setCursor(Cursor.HAND); //鼠标移入添加小手图案
        twoBtn.setOnMouseClicked(enpPageAction);

        Button threeBtn = new Button("3");
        threeBtn.setCursor(Cursor.HAND); //鼠标移入添加小手图案
        threeBtn.setOnMouseClicked(enpPageAction);

        Button fourBtn = new Button("4");
        fourBtn.setCursor(Cursor.HAND); //鼠标移入添加小手图案
        fourBtn.setOnMouseClicked(enpPageAction);

        Label nextLab = new Label("下一页>>");
        nextLab.setCursor(Cursor.HAND); //鼠标移入添加小手图案
        nextLab.setTextFill(rgb3);
        nextLab.setOnMouseClicked(enpPageAction);

        Label endLab = new Label("尾页>>");
        endLab.setCursor(Cursor.HAND); //鼠标移入添加小手图案
        endLab.setOnMouseClicked(enpPageAction);

        endLab.setTextFill(rgb3);
        Label allLab = new Label("总记录数100条");
        TextField pageTF = new TextField();
        pageTF.setPrefWidth(20);
        Label pageLab = new Label("/10");
        Button goBtn = new Button("GO");
        goBtn.setCursor(Cursor.HAND); //鼠标移入添加小手图案
        hBox2.getChildren().addAll(firstLab,upLab,oneLab,twoBtn,threeBtn,fourBtn,nextLab,endLab,allLab,pageTF,pageLab,goBtn);


        this.getChildren().add(hBox2);

    }
}
